import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
// 利用工厂函数 避免状态污染
export const createRouter = () => {
    const router = new Router({
        mode: 'history', // 兼容前后端
        routes: [
            {
                name: 'home',
                path: '/',
                component: () => import('@/pages/home.vue')
            },{
                name: 'about',
                path: '/about',
                component: () => import('@/pages/about.vue')
            },{
                name: 'posts',
                path: '/posts',
                component: () => import('@/pages/posts.vue')
            },{
                name: '404',
                path: '*',
                component: () => import('@/pages/404.vue')
            }
        ]
    })
    return router
}